﻿<%@ Application Language="C#" %>

<script runat="server">
    System.IO.FileSystemWatcher Watcher = new System.IO.FileSystemWatcher();
    
    void Application_Start(object sender, EventArgs e) 
    {        
        Watcher.Path = Server.MapPath("Data");
        Watcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.DirectoryName;
        Watcher.Filter = "*.txt";
        Watcher.EnableRaisingEvents = true;
        Watcher.Created += Watcher_Created;
    }

    void Watcher_Created(object sender, System.IO.FileSystemEventArgs e)
    {
        FileWatcher fw = new FileWatcher(Watcher);
        fw.DownloadFile(e.FullPath);
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    {
        System.Web.HttpRuntime.UnloadAppDomain();
    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
